//
//  WRYLoginController.m
//  BaiSiBuJie
//
//  Created by wry on 16/4/29.
//  Copyright © 2016年 WRY. All rights reserved.
//

#import "WRYLoginController.h"
#import "WRYMiddleView.h"
#import "WRYFastLoginView.h"

@interface WRYLoginController ()
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIView *middleVIew;//中间块view
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftMiddleViewConstraint;//middleView的左边约束

@end

@implementation WRYLoginController
-(void)viewDidLoad
{
    [super viewDidLoad];
    
    // 添加登录view:如果一个view通过xib加载，默认根xib尺寸一样
    // 在viewDidLoad不会执行子控件约束

    WRYMiddleView *loginMiddleView=[WRYMiddleView loginMiddleView];
    WRYMiddleView *registerMiddleView=[WRYMiddleView registerMiddleView];
    
    [self.middleVIew addSubview:loginMiddleView];
    
    [self.middleVIew addSubview:registerMiddleView];
    
    WRYFastLoginView*fastLoginView=[WRYFastLoginView fastLogInView];
    [self.bottomView addSubview:fastLoginView];
}
//执行约束
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    // 设置登录view
    
    WRYMiddleView *loginView=self.middleVIew.subviews[0];
    loginView.frame=CGRectMake(0, 0, self.middleVIew.width/2, self.middleVIew.height);
    // 注册view

    WRYMiddleView *registView=self.middleVIew.subviews[1];
registView.frame=CGRectMake(self.middleVIew.width/2, 0, self.middleVIew.width/2, self.middleVIew.height);
    
    //快速登陆view
    WRYFastLoginView*fastLoginView=self.bottomView.subviews[0];
    fastLoginView.frame=self.bottomView.bounds;
}


//点击dismiss按钮
- (IBAction)dismissBtnClick:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

// 点击注册按钮
- (IBAction)registerBtnClick:(UIButton *)sender {
    //按钮变化
    sender.selected= !sender.selected;
    
    //middleview变化
   _leftMiddleViewConstraint.constant= ( _leftMiddleViewConstraint.constant==0)? -self.middleVIew.width/2 : 0;
    
    //自动布局
    [UIView animateWithDuration:0.2 animations:^{
        [self.view layoutIfNeeded];
    }];
    

}
/**
 *  点击屏幕就退出编辑
 */
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

    [self.view endEditing:YES];
}
@end
